package com.ruoyi.project.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysTabbar;
import com.ruoyi.project.system.service.ISysTabbarService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 微信菜单Controller
 *
 * @author hongwj
 * @date 2024-03-07
 */
@RestController
@RequestMapping("/system/tabbar")
@Slf4j
public class SysTabbarController extends BaseController {
    @Autowired
    private ISysTabbarService sysTabbarService;

    /**
     * 查询微信菜单列表
     */
    @PreAuthorize("@ss.hasPermi('system:tabbar:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysTabbar sysTabbar) {
        startPage();
        List<SysTabbar> list = sysTabbarService.selectSysTabbarList(sysTabbar);
        return getDataTable(list);
    }

    /**
     * 查询所有微信菜单列表
     */
    @PreAuthorize("@ss.hasPermi('system:tabbar:all')")
    @Log(title = "微信菜单", businessType = BusinessType.OTHER)
    @GetMapping("/all/tabbars")
    public AjaxResult all(SysTabbar sysTabbar) {
        List<SysTabbar> list = sysTabbarService.selectSysTabbarList(sysTabbar);
        return success(list);
    }

    /**
     * 导出微信菜单列表
     */
    @PreAuthorize("@ss.hasPermi('system:tabbar:export')")
    @Log(title = "微信菜单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysTabbar sysTabbar) {
        List<SysTabbar> list = sysTabbarService.selectSysTabbarList(sysTabbar);
        ExcelUtil<SysTabbar> util = new ExcelUtil<SysTabbar>(SysTabbar.class);
        util.exportExcel(response, list, "微信菜单数据");
    }

    /**
     * 获取微信菜单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tabbar:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysTabbarService.selectSysTabbarById(id));
    }

    /**
     * 新增微信菜单
     */
    @PreAuthorize("@ss.hasPermi('system:tabbar:add')")
    @Log(title = "微信菜单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysTabbar sysTabbar) {
        return toAjax(sysTabbarService.insertSysTabbar(sysTabbar));
    }

    /**
     * 修改微信菜单
     */
    @PreAuthorize("@ss.hasPermi('system:tabbar:edit')")
    @Log(title = "微信菜单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysTabbar sysTabbar) {
        return toAjax(sysTabbarService.updateSysTabbar(sysTabbar));
    }

    /**
     * 删除微信菜单
     */
    @PreAuthorize("@ss.hasPermi('system:tabbar:remove')")
    @Log(title = "微信菜单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysTabbarService.deleteSysTabbarByIds(ids));
    }
}
